<section class="content-header" >
    <h1>
        一键拨号
    </h1>
    <ol class="breadcrumb">
        <li><a href="{:U('/Admin/index')}"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">一键拨号</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >电话列表</label></div>
                    <div class="pull-right">
                        <button  class="btn btn-block btn-primary btn-sm "
                                onclick="add()"><i
                                class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;添加项目
                        </button>
                    </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>项目</th>
                                <th>电话</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    var dialTable;
    $(function () {
        dialTable = $('#table').dataTable({
            "autoWidth": true,
//            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
            'ordering': false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "searching": false,
            "ajax": {
                "url": "{:U('System/dial')}",
                "type": "POST"
            },
            "columns": [
                {"data": "id"},
                {"data": "name"},
                {"data": "mobile"},
                {"data": "id"}
            ],
            "columnDefs": [
                {
                    "targets": 3,
                    "render": function (data, type, row) {
                        return '<a href="javascript:add(' +data +')"><i class="fa fa-edit"></i>&nbsp;修改</a>&nbsp;&nbsp;' +
                                '<a href="javascript:delItem(' +data + ')"><i class="fa fa-trash-o"></i>&nbsp;删除</a>';
                    }
                }
             ],
            "language": lang
        });
    });

    function add(id){
        var url = "{:U('System/add_dial')}";
       if(id){
           url+="?id="+id;
       }
        $.dialog(url, '添加电话');
    }

    function delItem(id) {
        var title = '确定删除吗?';
        $.messager.confirm('提示信息', title, function (result) {
            if (!result) return false;
            $.post('{:U("System/del_dial")}', "id=" + id, function (res) {
                if (!res.status) {
                    $.messager.alert('提示信息', res.info, 'error');
                } else {
                    dialTable.fnDraw(false);
                }
            }, 'json');
        });
    }



</script>